<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="./Public/Admin/Bootstrap/Css/bootstrap.min.css" />
	
	<link rel="stylesheet" href="./Public/Admin/Css/common.css" />
	<script type="text/javascript" src='./Public/Admin/Js/jquery-1.7.2.min.js'></script>
	<style type="text/css">
		body{
			margin-bottom: 100px;
		}
	</style>
	<script>
	 		$(function(){
//	 			alert(1);
	 			$(".add").click(function(){
	 				
	 				// $.echo
	 				//var tid1=$('#id0 option:selected').attr('tid');
	 				//var tid2 = $('#id1 option:selected').attr('tid');
	 				var glstock=$('#glstock').val();
	 				var glnumber=$('#glnumber').val();
	 				var gid="<?php echo Q('get.gid')?>";
	 				//var vv = $("select option:selected").val();
	 				var obj = $("select option:selected");
	 			
	 				var combo='';
	 				for(var i=0;i<obj.length;i++){
//	 					console.log(obj[i].value);
//						combo.push(obj[i].value);
	 					combo+=obj[i].value+",";
					
	 				}
	 				console.log(combo);
	 				combo = combo.substring(0,combo.length-1);
	 				//console.log(obj[i].value);
	 				$.ajax({
	 					type:"post",
	 					url:"<?php echo U('GoodsList/add')?>",
	 					data:{combine: combo,glstock:glstock,glnumber:glnumber,goods_gid:gid},
	 					dataType:'text',
	 					success:function(phpData){
	 						console.log(phpData);
	 						if(phpData!= -1){
	 							var attr = '';
	 						//alert(phpData);
	 						attr+='<tr>';
	 						attr+='<td>'+phpData+'</td>';
	 						//attr+='<td>'+combo+'</td><td>56</td>';
	 						for(var i=0;i<obj.length;i++){
			 					attr+='<td>'+obj[i].innerText+'</td>';
//			 					console.log(obj[i].value);
		
			 				}
	 						attr+='<td>'+glstock+'</td><td>'+glnumber+'</td>';
	 						attr+='<td><a href="" class="btn btn-sm btn-warning">编辑</a>  <a href="" class="btn btn-sm btn-danger">删除</a></td></tr>';
	 						
	 						$("#attra").before(attr);
	 						}
	 						

	 					}
	 				})

	 				
	 			})
	 		})
	 	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<if condition="$is_show">
	</if>
		<table class='table table-bordered table-hover'>
			
			<tr>
				<th>货品ID</th>
				<?php foreach ($data as $v){?>
					<td><?php echo $v['taname']?></td>
				<?php }?>
				<th>库存</th>
				<th>货号</th>
				<th>操作</th>
			</tr>


            <?php foreach ($listData as $v){?>
        <tr>
        	
           		<td><?php echo $v['glid']?></td>
				<?php foreach ($v['value'] as $value){?>
                	<td ><?php echo $value['gavalue']?></td>
				<?php }?>


	            <td><?php echo $v['glstock']?></td>
	            <td><?php echo $v['glnumber']?></td>

	            
            <td>
	 
                <a href="<?php echo U('edit',array('glid'=>$v['glid'],'gid'=>$v['goods_gid']))?>" class="btn btn-sm btn-warning">编辑</a>
                <a href="<?php echo U('del',array('glid'=>$v['glid']))?>" class="btn btn-sm btn-danger">删除</a>
            </td>
        </tr>
			<?php }?>


			<!-- 如果已添加数目小于可能情况数目，才出现添加货品的输入框 -->
			<if condition="$is_show">
			<tr class="info" id="attra">
				<td>添加货品</td>
				<?php foreach ($data as $v){?>
				
					<td>
						<select name="">
							<option value="0">-请选择-</option>
							<?php foreach ($v['value'] as $value){?>
							
								<option value="<?php echo $value['gaid']?>"><?php echo $value['gavalue']?></option>
							<?php }?>
						</select>
					</td>
				<?php }?>


				<td>
					<input type="text" name='glstock' id='glstock'/>
				</td>
				<td>
					<input type="text" name='glnumber' id='glnumber'>
				</td>
				<td></td>
			</tr>
			</if>
		</table>

	<if condition="$is_show">
	
		<input type="submit" value='保存添加' class="btn btn-primary add"/>

	</if>

	</div>
	</div>
	</div>



</body>
</html>